<?php
class ModelCatalogReviewImage extends Model {
    public $table = 'review_image';

    public function insertReviewImages($review_id, $images)
    {
        $tbl = $this->getTable();
        
        $now = date('Y-m-d H:i:s');

        $insert_vals = [];
        foreach ($images as $image) {

            // 去除图片的http头和参数
            $this->load->model('tool/image');
            $image = $this->model_tool_image->deleteHeaderAndParameter($image);

            $insert_vals [] = [
                'review_id'  => $review_id,
                'image'      => $image,
                'date_added' => $now
            ];
        }

        $values_sql = $this->assembleValuesSql($insert_vals);

        $insert = "INSERT INTO $tbl $values_sql";

        return $this->db->query($insert);
	}

    public function findByReviewIds($review_ids)
    {
        $tbl = $this->getTable();

        $ids = "('" . implode("','", $review_ids) . "')";

        $query = $this->db->query("SELECT * FROM $tbl WHERE review_id IN $ids ");

        return $query->rows;
    }
}